﻿using EasyElasticLogger.NETFramework.ES.Configuration;
using EasyElasticLogger.NETFramework.ES.Logging;
using EasyElasticLogger.NETFramework.ES.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace EasyElasticLogger.Tests;

[TestClass]
public sealed class Test1
{
    [TestMethod]
    public void TestMethod1()
    {
        // 测试默认配置
        var config = ConfigurationProvider.Default();
        
        Assert.IsNotNull(config);
        Assert.IsTrue(config.Enabled);
        Assert.AreEqual("app-log", config.IndexPrefix);
        Assert.AreEqual(IndexStrategy.DailyRolling, config.IndexStrategy);
        Assert.IsNotNull(config.Cluster);
        Assert.IsNotNull(config.Cluster.Nodes);
        Assert.AreEqual(0, config.Cluster.Nodes.Count);
    }

    [TestMethod]
    public void TestStaticLoggerInitialize()
    {
        // 测试静态日志记录器初始化
        var customConfig = new LoggerConfiguration
        {
            IndexPrefix = "static-test",
            ApplicationName = "StaticTestApp",
            Enabled = true,
            Cluster = new ClusterConfiguration
            {
                Nodes = new List<string> { "http://localhost:9200" }
            }
        };

        // 初始化静态日志记录器
        ElasticLogger.Initialize(customConfig);

        // 验证静态日志记录器可以正常使用
        Assert.IsTrue(true); // 不抛出异常即为成功
    }

    [TestMethod]
    public void TestLogLevelEnum()
    {
        var debugLevel = LogLevel.Debug;
        var infoLevel = LogLevel.Info;
        var warnLevel = LogLevel.Warn;
        var errorLevel = LogLevel.Error;
        var fatalLevel = LogLevel.Fatal;

        Assert.AreEqual("DEBUG", debugLevel.ToStringValue());
        Assert.AreEqual("INFO", infoLevel.ToStringValue());
        Assert.AreEqual("WARN", warnLevel.ToStringValue());
        Assert.AreEqual("ERROR", errorLevel.ToStringValue());
        Assert.AreEqual("FATAL", fatalLevel.ToStringValue());
    }
}